package com.student.liu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.student.liu.entity.GoodsSpec;
import com.student.liu.mapper.IGoodsSpecMapper;
import com.student.liu.service.IGoodsSpecService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 商品规格 Service 实现类
 */
@Service
public class GoodsSpecServiceImpl extends ServiceImpl<IGoodsSpecMapper, GoodsSpec> implements IGoodsSpecService {

    @Resource
    IGoodsSpecMapper goodsSpecMapper;

    @Override
    public void subtractCount(Integer id, Integer count) {
        goodsSpecMapper.updateCount(id, count);
    }

    @Override
    public IPage<Map<String, Object>> goodsSpec(Integer pageIndex, Integer pageSize, Integer goodsId) {
        Page page = new Page(pageIndex, pageSize);
        QueryWrapper queryWrapper = new QueryWrapper();
        if (goodsId > 0) {
            //设置"goodsId"作为条件
            queryWrapper.eq("goods_id", goodsId);
        }
        queryWrapper.orderByAsc("id");
        return pageMaps(page, queryWrapper);
    }
}
